package com.aku.controller.page;

import com.aku.pojo.Book;
import com.aku.pojo.User;
import com.aku.service.BookService;
import com.aku.service.BorrowService;
import com.aku.service.StudentService;
import com.aku.vo.ShowBorrow;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/page/user")
public class PageUserController {

    @Resource
    private StudentService studentService;
    @Resource
    private BookService bookService;
    @Resource
    private BorrowService borrowService;

    @RequestMapping("/stuBorrowInfo")
    public String stuBorrowInfo  (
            @SessionAttribute("user") User user, Model model){
        List<ShowBorrow> borrowList = borrowService.searchBorrowByUsername(user.getUsername());
        model.addAttribute("user",user);
        model.addAttribute("borrowList",borrowList);
        return "/stu/stu_borrowInfo";
    }

    @RequestMapping("/stuBookInfo")
    public String stuBookInfo  (
            @SessionAttribute("user") User user, Model model){
        List<Book> books = bookService.findAllBook();
        model.addAttribute("user",user);
        model.addAttribute("books",books);
        return "/stu/stu_bookInfo";
    }

}
